<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="description" content="后台管理">
    <!-- Twitter meta-->
    <title>用户管理</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Main CSS-->
    <link rel="stylesheet" type="text/css" href="../../public/admin/css/main.css">
    <!-- Font-icon css-->
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <style>
        td{background-color: #dff0d8;}
    </style>
</head>
<body class="app sidebar-mini rtl">
<?php if(!empty($_COOKIE['uname']) && !empty($_COOKIE['auth'])) { ?>
<?php require 'menu.php'?>
<!-- Sidebar menu-->
    <main class="app-content">
        <div class="app-title">
            <div>
                <h1><i class="fa fa-dashboard"></i> 首页</h1>
            </div>
            <ul class="app-breadcrumb breadcrumb">
                <li class="breadcrumb-item"><i class="fa fa-home fa-lg"></i></li>
                <li class="breadcrumb-item"><a href="../admin.php">首页</a></li>
            </ul>
        </div>
        <tr>
            <td width="99%" valign="top" align="left">您的位置：用户管理</td>
        </tr>
        <div class="list-group" >
            <div class="list-group-item active" style="margin-bottom: 10px">
                <form method="post" action='contro_user.php?a=search' style="float: left">
                    <span>用户名：</span>
                    <input style="color: #000" type="hidden" name="auth" value="<?php echo @$_COOKIE['auth'] ?>">
                    <input style="color: #000" type="text" name="name" value="<?php echo @$_GET['search'] ?>"
                           class="text-word">
                    <input type="submit" value="查询" class="text-but">
                </form>
                <button style='border: none;background: none; float: right; color: #fff'
                        onclick="member_add('新增用户','add_list.php','600','500')">
                    新增用户
                </button>
            </div>

            <table class="table table-bordered">

                <thead>
                <tr align="center" style="background: #fff">
                    <th>
                        id
                    </th>
                    <th>
                        用户名
                    </th>
                    <th>
                        权限
                    </th>
                    <th>
                        锁定
                    </th>
                    <th>
                        最后登录时间
                    </th>
                    <th>
                        操作
                    </th>
                </tr>
                </thead>
                <?php
                require 'config.php';
                $auth = $_COOKIE['auth'] == '超级管理员' ? 3 : 2;
                if ($auth == 3) {
                    if (!empty($_GET['search'])){
                        $search = $_GET['search'];
                        $sql = "select * from user where userName like '%{$search}%' having  auth<3";
                        $result = mysqli_query($link,$sql);
                        //查询所有的数据总条数；
                        $num_All = mysqli_num_rows($result);
                        //分页几条；
                        $page = 4;
                        //分几页,总页数；
                        $page_All = ceil($num_All/$page);
                        //判断p是否有值；
                        if(empty($_GET['p'])){
                            $p = 1;
                        }else{
                            $p = $_GET['p'];
                        }
                        $page_num = ($p-1)*$page;
                        $sql = "select * from user where auth<3 and userName like '%{$search}%' limit {$page_num},{$page} ";
                        $result = mysqli_query($link, $sql);
                        $num = ($p-1)*$page;
                        while($rows = mysqli_fetch_assoc($result)){
                            $auth_name = $rows['auth'];
                            if ($auth_name == 0) {
                                $auth_name = '普通用户';
                            }
                            if ($auth_name == 1) {
                                $auth_name = '会员用户';
                            }
                            if ($auth_name == 2) {
                                $auth_name = '管理员';
                            }
                            $status = $rows['status'] == 1 ? '开启' : '禁用';
                            $id = $rows['id'];
                            $pwd = $rows['password'];
                            $name =$rows['userName'];
                            $num++;
                            echo "<tr align='center' class='info'>";
                            echo "<td>{$rows['id']}</td>";
                            echo "<td>{$rows['userName']}</td>";
                            echo "<td>{$auth_name}</td>";
                            echo "<td>{$status}</td>";
                            echo "<td>{$rows['lastlogin']}</td>";
                            echo "<td>";
                            echo " <button style='border: none;background: none;'  onclick=\"member_add('编辑','update_user.php?name={$name}&pwd={$pwd}&id={$id}&auth={$auth}&authname={$auth_name}','800','600')\">
                                           编辑</button>&nbsp;&nbsp;";
                            echo "<a href='contro_user.php?a=del&id={$id}&p={$p}'>删除</a>&nbsp;&nbsp;";
                            if ($status == "开启") {
                                echo " <a href='contro_user.php?a=fen_jin&id={$id}&search={$search}&p={$p}'>禁用</a>";
                            } else {
                                echo " <a href='contro_user.php?a=fen_kai&id={$id}&search={$search}&p={$p}'>开启</a>&nbsp;&nbsp;";
                            }

                            echo "</td>";
                            echo "</tr>";
                        }
                        mysqli_free_result($result);
                        mysqli_close($link);
                    }
                    else{
                        $sql = "select * from user where auth<2";
                        $result = mysqli_query($link, $sql);
                        //查询所有的数据总条数；
                        $num_All = mysqli_num_rows($result);
                        //分页几条；
                        $page = 4;
                        //分几页,总页数；
                        $page_All = ceil($num_All / $page);
                        //判断p是否有值；
                        if (empty($_GET['p'])) {
                            $p = 1;
                        } else {
                            $p = $_GET['p'];
                        }
                        $page_num = ($p - 1) * $page;
                        $sql = "select * from user where auth<3 limit {$page_num},{$page}";
                        $result = mysqli_query($link, $sql);
                        $num = ($p-1)*$page;
                        while ($rows = mysqli_fetch_assoc($result)) {
                            $auth_name = $rows['auth'];
                            if ($auth_name == 0) {
                                $auth_name = '普通用户';
                            }
                            if ($auth_name == 1) {
                                $auth_name = '会员用户';
                            }
                            if ($auth_name == 2) {
                                $auth_name = '管理员';
                            }
                            $status = $rows['status'] == 1 ? '开启' : '禁用';
                            $id = $rows['id'];
                            $pwd = $rows['password'];
                            $name =$rows['userName'];
                            echo "<tr align='center' class='info'>";
                            echo "<td class='success'>{$rows['id']}</td>";
                            echo "<td class='success'>{$rows['userName']}</td>";
                            echo "<td class='success'>{$auth_name}</td>";
                            echo "<td class='success'>{$status}</td>";
                            echo "<td class='success'>{$rows['lastlogin']}</td>";
                            echo "<td class='success'>";
                            echo " <button style='border: none;background: none;'  onclick=\"member_add('编辑','update_user.php?name={$name}&pwd={$pwd}&id={$id}&auth={$auth}&authname={$auth_name}','800','600')\">
                                           编辑</button>&nbsp;&nbsp;";
                            echo "<a href='contro_user.php?a=del&id={$id}&p={$p}'>删除</a>&nbsp;&nbsp;";
                            if ($status == "开启") {
                                echo " <a href='contro_user.php?a=jin&id={$id}&p={$p}'>禁用</a>";
                            } else {
                                echo " <a href='contro_user.php?a=kai&id={$id}&p={$p}'>开启</a>&nbsp;&nbsp;";
                            }

                            echo "</td>";
                            echo "</tr>";
                        }
                        mysqli_free_result($result);
                        mysqli_close($link);
                    }
                }

                if ($auth == 2) {
                    if (!empty($_GET['search'])){
                        $search = $_GET['search'];
                        $sql = "select * from user where userName like '%{$search}%' having  auth<2";
                        $result = mysqli_query($link,$sql);
                        //查询所有的数据总条数；
                        $num_All = mysqli_num_rows($result);
                        //分页几条；
                        $page = 4;
                        //分几页,总页数；
                        $page_All = ceil($num_All/$page);
                        //判断p是否有值；
                        if(empty($_GET['p'])){
                            $p = 1;
                        }else{
                            $p = $_GET['p'];
                        }
                        $page_num = ($p-1)*$page;
                        $sql = "select * from user where auth<2 and userName like '%{$search}%' limit {$page_num},{$page} ";
                        $result = mysqli_query($link, $sql);
                        $num = ($p-1)*$page;
                        while($rows = mysqli_fetch_assoc($result)){
                            $auth_name = $rows['auth'];
                            if ($auth_name == 0) {
                                $auth_name = '普通用户';
                            }
                            if ($auth_name == 1) {
                                $auth_name = '会员用户';
                            }
                            if ($auth_name == 2) {
                                $auth_name = '管理员';
                            }
                            $status = $rows['status'] == 1 ? '开启' : '禁用';
                            $id = $rows['id'];
                            $pwd = $rows['password'];
                            $name =$rows['userName'];
                            $num++;
                            echo "<tr align='center' class='info'>";
                            echo "<td>{$rows['id']}</td>";
                            echo "<td>{$rows['userName']}</td>";
                            echo "<td>{$auth_name}</td>";
                            echo "<td>{$status}</td>";
                            echo "<td>{$rows['lastlogin']}</td>";
                            echo "<td>";
                            echo " <button style='border: none;background: none;'  onclick=\"jquery:alert('你目前没有权限')\">
                                           编辑</button>&nbsp;&nbsp;";
                            echo "<a href='contro_user.php?a=del&id={$id}&p={$p}'>删除</a>&nbsp;&nbsp;";
                            if ($status == "开启") {
                                echo " <a href='contro_user.php?a=fen_jin&id={$id}&search={$search}&p={$p}'>禁用</a>";
                            } else {
                                echo " <a href='contro_user.php?a=fen_kai&id={$id}&search={$search}&p={$p}'>开启</a>&nbsp;&nbsp;";
                            }

                            echo "</td>";
                            echo "</tr>";
                        }
                        mysqli_free_result($result);
                        mysqli_close($link);
                    }
                    else{
                        $sql = "select * from user where auth<2";
                        $result = mysqli_query($link, $sql);
                        //查询所有的数据总条数；
                        $num_All = mysqli_num_rows($result);
                        //分页几条；
                        $page = 4;
                        //分几页,总页数；
                        $page_All = ceil($num_All / $page);
                        //判断p是否有值；
                        if (empty($_GET['p'])) {
                            $p = 1;
                        } else {
                            $p = $_GET['p'];
                        }
                        $page_num = ($p - 1) * $page;
                        $sql = "select * from user where auth<2 limit {$page_num},{$page}";
                        $result = mysqli_query($link, $sql);
                        $num = ($p-1)*$page;
                        while ($rows = mysqli_fetch_assoc($result)) {
                            $auth_name = $rows['auth'];
                            if ($auth_name == 0) {
                                $auth_name = '普通用户';
                            }
                            if ($auth_name == 1) {
                                $auth_name = '会员用户';
                            }
                            if ($auth_name == 2) {
                                $auth_name = '管理员';
                            }
                            $status = $rows['status'] == 1 ? '开启' : '禁用';
                            $id = $rows['id'];
                            $pwd = $rows['password'];
                            $name =$rows['userName'];
                            echo "<tr align='center' class='info'>";
                            echo "<td class='success'>{$rows['id']}</td>";
                            echo "<td class='success'>{$rows['userName']}</td>";
                            echo "<td class='success'>{$auth_name}</td>";
                            echo "<td class='success'>{$status}</td>";
                            echo "<td class='success'>{$rows['lastlogin']}</td>";
                            echo "<td class='success'>";
                            echo " <button style='border: none;background: none;'  onclick=\"jquery:alert('你目前没有权限')\">
                                           编辑</button>&nbsp;&nbsp;";
                            echo "<a href='contro_user.php?a=del&id={$id}&p={$p}'>删除</a>&nbsp;&nbsp;";
                            if ($status == "开启") {
                                echo " <a href='contro_user.php?a=jin&id={$id}&p={$p}'>禁用</a>";
                            } else {
                                echo " <a href='contro_user.php?a=kai&id={$id}&p={$p}'>开启</a>&nbsp;&nbsp;";
                            }

                            echo "</td>";
                            echo "</tr>";
                        }
                        mysqli_free_result($result);
                        mysqli_close($link);
                    }
                }

                ?>
            </table>

            <div class="page" style="text-align: right">
                当前<?php echo $p;?>/<?php echo $page_All;?>页 总条数：<?php echo $num_All;?>条&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <a href="./user.php?p=1&search=<?php echo @$search?>">首页</a>&nbsp;&nbsp;&nbsp;
                <a href="./user.php?p=<?php echo $p<=1?1:($p-1)?>&search=<?php echo @$search?>">上一页</a>&nbsp;&nbsp;&nbsp;
                <a href="./user.php?p=<?php echo $p>=$page_All?$page_All:($p+1)?>&search=<?php echo @$search?>">下一页</a>&nbsp;&nbsp;&nbsp;
                <a href="./user.php?p=<?php echo $page_All;?>&search=<?php echo @$search?>">尾页</a>&nbsp;&nbsp;&nbsp;
            </div>
        </div>

    </main>

    <script src="../../public/admin/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/Swiper/3.4.2/js/swiper.jquery.min.js"></script>
    <script src="../../public/admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../public/admin/js/xadmin.js"></script>
    <script src="../../public/admin/js/popper.min.js"></script>
    <script src="../../public/admin/js/bootstrap.min.js"></script>
    <script src="../../public/admin/js/main.js"></script>
    <script src="../../public/admin/js/plugins/pace.min.js"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/Swiper/3.4.2/js/swiper.jquery.min.js"></script>
    <script src="../../public/admin/js/lib/layui/layui.js" charset="utf-8"></script>
    <?php
}else{
    echo "<script>alert('你还没登录');window.location.href='../index.php';</script>";die;
}
?>
<script>
    function x_admin_show(title,url,w,h){
        if (title == null || title == '') {
            title=false;
        };
        if (url == null || url == '') {
            url="404.html";
        };
        if (w == null || w == '') {
            w=800;
        };
        if (h == null || h == '') {
            h=($(window).height() - 50);
        };
        layer.open({
            type: 2,
            area: [w+'px', h +'px'],
            fix: false, //不固定
            maxmin: true,
            shadeClose: true,
            shade:0.4,
            title: title,
            content: url
        });
    }
    function member_add(title,url,w,h){
        x_admin_show(title,url,w,h);
    }
    
</script>
</body>
</html>
